<template>
  <div class="md:flex">
    <template v-for="(item, index) in growCardList" :key="item.title">
      <Card
        size="small"
        :loading="loading"
        :title="item.title"
        class="md:w-1/4 w-full !md:mt-0 !mt-4"
        :class="[index + 1 < 4 && '!md:mr-4']"
        :canExpan="false"
      >
        <template #extra>
          <Tag :color="item.color">{{ item.action }}</Tag>
        </template>

        <div class="py-4 px-4 flex justify-between">
          <CountTo prefix="￥" :decimals="2" :startVal="0" :endVal="item.value" class="text-2xl" />
          <Icon :icon="item.icon" :size="40" />
        </div>

        <div class="p-2 px-4 flex justify-between">
          <span>总{{ item.title }}</span>
          <CountTo prefix="￥" :decimals="2" :startVal="0" :endVal="item.total" />
        </div>
      </Card>
    </template>
  </div>
</template>
<script lang="ts" setup>
import {ref, onMounted} from 'vue';
import {CountTo} from '/@/components/CountTo/index';
import {Icon} from '/@/components/Icon';
import {Card, Tag} from 'ant-design-vue';
import {growCardList} from '../data';
import {queryMoneyStatistics} from '../api';

  defineProps({
    loading: {
      type: Boolean,
    },
  });

  onMounted(async () => {
    initMoneyStatistics();
  });

  /**
   * 获取资金统计
   */
  function initMoneyStatistics() {
    queryMoneyStatistics(null).then((res) => {
      if (res.success) {
        growCardList.forEach((item,index) => {
          if (index == 0) {
            item.total = res.result.rechargeTotalAmount;
            item.value = res.result.rechargeTotalAmountMonth;
          } else if (index == 1) {
            item.total = res.result.issuedTotalAmount;
            item.value = res.result.issuedTotalAmountMonth;
          } else if (index == 2) {
            item.total = res.result.billTotalAmount;
            item.value = res.result.billTotalAmountMonth;
          } else if (index == 3) {
            item.total = res.result.refundAmount;
            item.value = res.result.refundAmountMonth;
          }
        });
      }
    });
  }
</script>
